import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 * @User: vitobo
 * @Date: 2024-07-03
 * @Description: Lambda表达式学习
 */

//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}


public class Test {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("hello", 2);
        map.put("abc", 12);
        map.put("def", 21);
        map.put("opp", 5);

        map.forEach((key,val)->System.out.println("key: "+key+" val: "+val));
    }

    public static void main8(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("world");
        list.add("byte");

        list.forEach(s-> System.out.println(s));
        System.out.println("+++++++++++++++");

        list.sort((x,y)->x.compareTo(y));
        list.forEach(s-> System.out.println(s));
    }

    public static void main7(String[] args) {
        int a = 10;
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println(a);
            }
        };

        noParameterNoReturn.test();

        NoParameterNoReturn noParameterNoReturn12 = ()->{
            System.out.println("test方法");
        };
        noParameterNoReturn12.test();

    }
    public static void main6(String[] args) {
        MoreParameterReturn moreParameterReturn = (x,y)->x+y;
        System.out.println(moreParameterReturn.test(7,9));
    }

    public static void main5(String[] args) {
        OneParameterReturn oneParameterReturn = x->x+1;
    }

    public static void main4(String[] args) {
        NoParameterReturn noParameterReturn = ()->10;
        int ret = noParameterReturn.test();
        System.out.println(ret);
    }

    public static void main3(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn = (x,y)-> System.out.println(x+y);
        moreParameterNoReturn.test(1,2);
    }

    public static void main2(String[] args) {
        OneParameterNoReturn oneParameterNoReturn = x-> System.out.println(x);
        oneParameterNoReturn.test(10);
    }

    public static void main1(String[] args) {
        int a = 10;
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("这是test方法");
                System.out.println(a);
            }
        };
        noParameterNoReturn.test();
    }
}
